<?php
class Products extends MX_Controller
{
    function __construct()
    {
        parent::__construct(); 
        $this->load->model('Restaurentmenus_model'); 
    }
     function index($restairent_id = 0)//+add category
    {                          
        $term_taxonomy = new Term_taxonomy();
        $term_taxonomy->where('restaurent_id',$restairent_id);
        $term_taxonomy->where('parent_term',0)->get();
        $restaurent_menu = $term_taxonomy->term_id;
        
        $restaurent = new Restaurent();
        $data['restaurent'] = $restaurent->get_by_id($restairent_id);
        
        $data['list_res_menu'] = $this->Restaurentmenus_model->get_res_menu($restaurent_menu,0);        
        $this->common->load_template('products_index',$data);
    } 
    function index1($restaurent_id = '~',$keyword = '~', $row = 0)
    {
        $product = new Product();
        
        $data['key_word'] = urldecode($keyword);
        if($this->input->post('txtKeyWord'))
        {
            $data['key_word'] = $this->input->post('txtKeyWord');
        }       
        //paging
        include('paging.php');        		                                 
        $data['restaurent_id'] = $restaurent_id;
        // compute total record     
        if($this->input->post('restaurent_id'))
        {
            $data['restaurent_id'] = $this->input->post('restaurent_id');
        }
        //echo $data['restaurent_id'];
        if($data['key_word'] != '~')
        {
            $product->like('name', $data['key_word']);
        }
        if ($data['restaurent_id'] != '~')
        {
            $product->where('restaurent_id',$data['restaurent_id']);
        } 
        $config['base_url']= base_url()."products/products/index/".$data['restaurent_id'].'/'.$data['key_word'].'/';
        $config['total_rows'] = $product->count();        
        $config['cur_page'] = $row;		
        $this->pagination->initialize($config);
        $data['list_link'] = $this->pagination->create_links();	
        
        $product = new Product();
        $product->limit($config['per_page'], $row)
            ->order_by('id','DESC');                        
        if($data['key_word'] != '~')
        {
            $product->like('name', $data['key_word']);
        }
        if ($data['restaurent_id'] != '~')
        {
            $product->where('restaurent_id',$data['restaurent_id']);
        }               
        $data['list_product'] = $product->get();        
        // get list restaurent
        $res = new Restaurent();
        $data['list_res'] = $res->get();
                
        $this->common->load_template('products_index1',$data);
    }
    function detail($id = 0)
    {
       $product = new Product();
       $data['product'] = $product->get_by_id($id);
       $this->common->load_template('products_detail',$data); 
    }
    function ajax_show_detail()
    {
        $id = $this->input->post('id');
        $product = new Product();
        $product->get_by_id($id);
        $data = ''; 
        $data.='<div class="view_food_ajax">';
        $data.='<div class="avatar_ajax">';
        $data.='<a href="#"><img alt="'.$product->name.'" src="'.$product->image.'" /></a>';
        $data.='</div>';
        $data.='<div class="food_name_ajax">';            			
        $data.='<a href="#"><span >'.$this->common->get_lang($product->name).'</span></a>';            			
        $data.='</div>';                       
        $data.='<div class="des_food_ajax">';
        $data.='<span>'.$product->description.'</span>';
        //$data.='<br/><div class="time_foods">';            						
        //$data.='Mở cửa : 08h:30 - 20h:00';
        //$data.='</div>';
        $data.='</div>' ;
        $data.='<div class="price_food_ajax">';
        $data.='<span>Giá :  '.$product->price.' VNĐ</span>';         
        $data.='</div></div>';
        echo $data;
    }    
}
?>